package org.mybatis.test;

import org.mybatis.binding.MapperProxyFactory;
import org.mybatis.binding.MapperRegistry;
import org.mybatis.session.SqlSession;
import org.mybatis.session.SqlSessionFactory;
import org.mybatis.session.defaults.DefaultSqlSessionFactory;
import org.mybatis.test.dao.IUserDao;

import java.util.HashMap;
import java.util.Map;


public class Main {
    public static void main(String[] args) {
        // 1. 注册Mapper
        MapperRegistry registry = new MapperRegistry();
        registry.addMappers("org.mybatis.test.dao");

        // 2. 从 SqlSession 工厂获取 SqlSession
        SqlSessionFactory sqlSessionFactory = new DefaultSqlSessionFactory(registry);
        SqlSession sqlSession = sqlSessionFactory.openSession();

        // 3. 获取映射器对象
        IUserDao userDao = sqlSession.getMapper(IUserDao.class);

        // 4. 测试验证
        String res = userDao.queryUserName("10001");
        System.out.println(res);
    }
}









































